package com.jp.knowledge.my.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.gson.JsonObject;
import com.jp.knowledge.adapter.SearchTeamCircleAdapter;
import com.jp.knowledge.adapter.team_circle.TeamCircleAdapter;
import com.jp.knowledge.comm.JpApplication;
import com.jp.knowledge.fragment.TeamCircleDataShowFragment;
import com.jp.knowledge.http.HttpHelper;
import com.jp.knowledge.model.TeamCircleModel;
import com.jp.knowledge.model.UserData;
import com.jp.knowledge.my.adapter.MyCommetsAdapter;

import java.util.ArrayList;

/**
 * Created by 528787067@qq.com on 2017/5/8.
 */

public class MyCommentsFragment extends TeamCircleDataShowFragment {

    public static MyCommentsFragment newInstance(UserData userData, int type){
        MyCommentsFragment myCommentsFragment = new MyCommentsFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("userData", userData);
        bundle.putInt("type", type);
        myCommentsFragment.setArguments(bundle);
        return myCommentsFragment;
    }

    private int type;
    private UserData userData;
    private int page;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        userData = (UserData) bundle.getSerializable("userData");
        type = bundle.getInt("type");
        super.onCreate(savedInstanceState);
        page = 1;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        canRefreshLayout.setLoadMoreEnabled(false);
        return contentView;
    }

    @Override
    protected void initCachePath() {
        cachePath = getContext().getCacheDir().getPath() + "/my_comments" + HttpHelper.uuid + "_" + type;
        if (userData != null)
            cachePath += ("_" + userData.getUuid());
        cachePath += ".dat";
    }

    @Override
    protected void initAdapter() {
        teamCircleAdapter = new MyCommetsAdapter(context, teamCircleModels);
    }

    @Override
    protected void getData(int type, int mode) {
        JsonObject param = new JsonObject();
        if(mode == MODE_0)
            page = 1;
        else
            page += 1;
        param.addProperty("page", page);
        param.addProperty("type", MyCommentsFragment.this.type);
        HttpHelper.getInstance(context).myComments(param, 10 + mode, this);
    }

    @Override
    protected void updateRemindView() {
        teamCircleHeader.setVisibility(View.GONE);
    }
}
